package com.suypower.carManage.action;

import com.jarp.db.DAO;
import com.opensymphony.xwork2.ActionSupport;
import com.suypower.carManage.comm.ConstUtil;

import javax.servlet.ServletException;

/**
 * Created by zhaoyuan on 14-2-18.
 */
public class UserAction extends ActionSupport {

    private String NAME;
    private String USERNAME;
    private String PASSWORD;
    private String USERID;

    public String execute() {
        String res = "";
        DAO dao=new DAO();
        String sql="";
        if (USERID!=null&&!USERID.equals("")){
            sql="UPDATE dbo.tb_user SET name = '"+NAME+"',password = '"+PASSWORD+"',userName = '"+USERNAME+"' WHERE userid = "+USERID;
        }else{
            sql="INSERT INTO tb_user(name,password,userName)VALUES('"+NAME+"','"+PASSWORD+"','"+USERNAME+"')";
        }
        try {
            int count=dao.execCommand(ConstUtil.DBNAME,sql);
            if(count>0){
                res=SUCCESS;
            }else{
                res=ERROR;
            }
        } catch (ServletException e) {
            res=ERROR;
            e.printStackTrace();
        }
        return res;
    }

    public String getNAME() {
        return NAME;
    }

    public void setNAME(String NAME) {
        this.NAME = NAME;
    }

    public String getUSERNAME() {
        return USERNAME;
    }

    public void setUSERNAME(String USERNAME) {
        this.USERNAME = USERNAME;
    }

    public String getPASSWORD() {
        return PASSWORD;
    }

    public void setPASSWORD(String PASSWORD) {
        this.PASSWORD = PASSWORD;
    }

    public String getUSERID() {
        return USERID;
    }

    public void setUSERID(String USERID) {
        this.USERID = USERID;
    }
}
